package com.yezao.yzrouter.schemaparser

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore

/**
 * 负责跳转到 系统应用
 * 1、使用系统浏览器加载网页
 * 2、使用进入其他系统应用
 *
 * schema = system
 *
 * */
class SystemSchemaParser(mSchema: String) : AbsSchemaParser(mSchema) {
    override fun parseIntent(context: Context, webUrl: String,bundle: Bundle): Intent? {
        val intent = Intent(Intent.ACTION_VIEW).apply {
            setData(Uri.parse(webUrl))
        }
        //检查
        val resolveActivity =
            intent.resolveActivity(context.packageManager)
        return if (resolveActivity != null) {
            intent
        } else {
            null
        }
    }

    override fun getIntentAction(host:String):String{
        return when(host){
            "web"->Intent.ACTION_VIEW
            "contract"->Intent.ACTION_PICK
            "message"->Intent.ACTION_SEND
            "camera"-> MediaStore.ACTION_IMAGE_CAPTURE
            "video"-> MediaStore.ACTION_VIDEO_CAPTURE
            "playvideo"->Intent.ACTION_VIEW
            else->""
        }
    }


}